using Unity.Burst;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;

partial struct EnemyMoveControlSystem : ISystem
{
    [BurstCompile]
    public void OnCreate(ref SystemState state)
    {

    }

    [BurstCompile]
    public void OnUpdate(ref SystemState state)
    {
        if(SystemAPI.TryGetSingletonEntity<PlayerControlComponent>(out Entity player)){
            var playerTrans=SystemAPI.GetComponentRO<LocalTransform>(player);
        foreach((var trans,var moveData) in SystemAPI.Query<RefRW<LocalTransform>,RefRW<MoveComponent>>().WithAll<EnemyComponent>()){
            float3 temp=math.normalize(playerTrans.ValueRO.Position-trans.ValueRO.Position);
            moveData.ValueRW.dir=temp;
            moveData.ValueRW.speed=2;
        }
        }
        

    }

    [BurstCompile]
    public void OnDestroy(ref SystemState state)
    {
        
    }
}
